<?php

/**
 * 
 *
 * @copyright  Copyright (c) 2011 Celebrio Software
 * @package    CelebrioMail
 */

namespace ApplicationsModule\ApplicationModule;

use \Nette\Object;
use Albireo\Application\ApplicationManager;
use Albireo\Application\Application;

/**
 *
 * @author Celebrio Software
 */
class ApplicationModel extends Object {
    
    private $model;
    
    public function __construct($user) {
        $this->model = new ApplicationManager($user);
        
        //$app = $this->model->getApplicationByName("Gallery");
        //$this->model->addApplicationToUser($app);
    }
    
    public function install ($id) {
        $app = new Application();
        $app->setId($id);
        $this->model->addApplicationToUser($app);
    }
    
    public function uninstall ($id) {
        $app = new Application();
        $app->setId($id);
        $this->model->deleteApplicationFromUser($app);
    }
    
    private function getApplications() {
        return $this->model->getApplications();
    }
    
    public function getInstalled() {
        return $this->model->getApplicationsForUser();
    }
    
    public function getNotInstalled() {
        $applications = $this->getApplications();
        $installed = $this->getInstalled();
        foreach ($installed as $app) {
            $applications->remove($app);
        }
        return $applications;
    }
}